package com.example.test.demo;

import java.util.Arrays;

/**
 * @author 晓果冻
 * @version 1.0
 * @date 2021/6/23 7:45
 */
public class Demo {
    public static void main(String[] args) {
        int[] a = {1,8,3,5,77,15,43,54112,12,15,5};
        int[] b = {1,8,3,5,77,15,43,54112,12,15,5};
        System.out.println("冒泡排序");
        Arrays.stream(Demo.maopaosort(a)).forEach(e->{
            System.out.println(e);
        });
        System.out.println("插入排序");
        Arrays.stream(Demo.charusort(b)).forEach(e->{
            System.out.println(e);
        });
    }
    public static int[] maopaosort(int arr[]){
       int temp = 0;
       for(int i = 0;i < arr.length-1;i++){
           for(int j= 0;j < arr.length -1;j++){
               if(arr[j] < arr[j+1]){
                   temp = arr[j+1];
                   arr[j+1] = arr[j];
                   arr[j] = temp;
               }
           }
       }
        return arr;
    }
    public static int[] charusort(int arr[]){
        int temp = 0;
        for(int i = 1;i < arr.length;i++){
            for(int j = i;j>0;j--){
                if(arr[j] > arr[j-1]){
                    temp = arr[j-1];
                    arr[j-1] = arr[j];
                    arr[j] = temp;
                }
            }
        }
        return arr;
    }
    public static int[] kuaisusort(int arr[],int left,int right){
        int l = left;
        int r = right;
        int p = arr[l];
        int temp = 0;
        while(l < r){
            while(l < r && arr[r] >= p){
                r--;
            }
            while(p > arr[l]){
                l++;
            }
            if(l >= r){
                break;
            }
            if(arr[r] < p){
              temp = arr[r];
              arr[r] = arr[l];
              arr[l] = temp;
              r--;
            }
            if(arr[l] > p){
                temp = arr[l];
                arr[l] = arr[r];
                arr[r] = temp;
                l++;
            }
        }
        return arr;
    }
}

